package com.dzsw.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegExpSample {

    public static void main(String[] args) {
        startWith();
    }

    private static void startWith() {
        String regExp = "^Tom.*";
        String str1 = "Tom is a cat.";
        String str2 = "Jerry is a mouse.";
        String str3 = "Tom";
        String str4 = "Tom_is_a_cat.";

        Pattern pattern = Pattern.compile(regExp);
        System.out.println("str1=" + pattern.matcher(str1).matches());
        System.out.println("str2=" + pattern.matcher(str2).matches());
        System.out.println("str3=" + pattern.matcher(str3).matches());
        System.out.println("str4=" + pattern.matcher(str4).matches());

        Matcher matcher = Pattern.compile("\\w+").matcher(str1);
        while (matcher.find()) {
            System.out.println("w=" + matcher.group());
        }


    }
}
